
app.controller('identityDataCtrl', ['$scope', function($scope) {
	var needNewPagination = true;
	getData(1);
	
	function getData(pageNo) {
		var param = {
			state: $("#handle-state").val(),
			realName: $.trim($("#real-name").val()),
			pageNo: pageNo,
			pageCount: 20,
		};
		AQ.callAQJSON("getIdentityData.do", param, function(result) {
			var data = result.data;
			$scope.$apply(function () {
				$scope.listData = data;
				if(pageNo == 1 && needNewPagination) {	//创建分页
					var num_entries = 500;
					Utils.newPagination("Pagination", num_entries, function(page_index, jq) {
						if(page_index == 0 && needNewPagination) {
							needNewPagination = false;
							return;
						}
						getData(page_index+1);
					});
				}
			});
		}, function(err, code) {
			Utils.msgDialog(err + "["+ code +"]");
		});
	}
	
	$("#query-data").click(function() {
        getData(1);
    });
	
	$scope.handleIdentity = function(item) {
		var content = '<div style="border:1px solid #4B9A4B; background:#DDEEDD; padding:5px; margin-bottom:20px;">' + 
				'<a href="fz/user.html?userName='+item.recommender_name+'" target="_blank">推荐人：</a>'+ item.recommender_name + 
				'<a href="javascript:void(0)" onclick="goQQ('+ item.recommender_qq +')" style="margin-left:50px;">推荐人QQ：</a>'+ item.recommender_qq +'<BR>' + 
				'<span>推姓名：'+ item.recommender_real_name +'</span><span style="padding-left:50px;">siteNo：'+ item.recommender_site_no +'</span></div>'+
				'<span>姓名：'+ item.real_name +'</span><span style="padding-left:25px;">QQ：'+ item.qq +'</span>'+
				'<span style="padding-left:25px;">用户ID:'+ item.user_id +'</span><BR><BR>' +
				'性别：<label><input type="radio" name="item-sex" value="1">男</label>&nbsp;&nbsp;&nbsp;' +
				'<label><input type="radio" name="item-sex" value="2">女</label><BR><BR>' +
				'生日：年<input type="text" id="item-y" style="width:60px">' +
				'月<input type="text" id="item-m" style="width:60px">' +
				'日<input type="text" id="item-d" style="width:60px"><BR><BR>' +
				'处理结果：<textarea id="item-result" style="border:1px solid #CCC; width:252px; height:80px;"></textarea>';
		Utils.checkDialog(content, "审核通过", "审核未通过", function() {
			submitData(item.id, item.real_name, item.qq, 2);
		}, function() {
			submitData(item.id, item.real_name, item.qq, 3);
		});
	}

}]);

//提交身份认证数据
function submitData(id, realName, qq, state) {
	var sex = $("input[name='item-sex']:checked").val();
	var birthday = $.trim($("#item-y").val()) +","+ $.trim($("#item-m").val()) +","+ $.trim($("#item-d").val());
	var handleResult = $.trim($("#item-result").val());
	
	var param = {
		id: id,
		realName: realName,
		qq: qq,
		sex: sex,
		birthday: birthday,
		state: state,
		handleResult: handleResult,
	};
	AQ.callAQJSON("handleIdentity.do", param, function(result) {
		$("#ID_"+id).parent("ul").remove();
	}, function(err, code) {
		Utils.msgDialog(err + "["+ code +"]");
	});
}

/**
 * 打开QQ
 */
function goQQ(qq) {
	location.replace("tencent://message/?uin="+ qq +"&Site=qq&Menu=yes");
}
